<template>
  <content-card class="box-card" needFilter show-reload title="调度日志" @reload="getList">
    <template slot="right">
    </template>
    <el-form ref="queryForm" :inline="true" :model="queryParams" class="search-form" label-suffix="：">
      <el-form-item label="执行结果" prop="status">
        <el-select v-model="queryParams.status" clearable placeholder="请选择执行结果">
          <el-option v-for="dict in localDict.quartz_result" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker v-model="queryParams.params.executeTime_begin" placeholder="选择日期" type="date"
                        value-format="yyyy-MM-dd"/>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker v-model="queryParams.params.executeTime_end" placeholder="选择日期" type="date"
                        value-format="yyyy-MM-dd"/>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" type="info" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="40"/>
      <el-table-column label="任务名称" min-width="150px" prop="jobName" show-overflow-tooltip/>
      <el-table-column label="任务分组" min-width="100px" prop="jobGroup">
        <template v-slot:default="scope">
          <dict-tag :options="localDict.quartz_group" :value="scope.row.jobGroup" show-label/>
        </template>
      </el-table-column>
      <!--      <el-table-column label="调用目标字符串" min-width="160px" prop="invokeTarget" show-overflow-tooltip/>-->
      <el-table-column label="执行结果" min-width="100px" prop="status">
        <template v-slot:default="scope">
          <dict-tag :options="localDict.quartz_result" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="执行时间" min-width="180px" prop="startTime"/>
      <el-table-column label="完成信息" min-width="180px" prop="stopTime"/>
      <el-table-column label="执行说明" min-width="240px" prop="jobMessage" show-overflow-tooltip/>
    </el-table>
    <pagination v-show="pageParam.total > 0" :limit.sync="pageParam.pageSize" :page-sizes="pageParam.options"
                :page.sync="pageParam.pageNum" :total="pageParam.total" @pagination="getList"/>

  </content-card>
</template>

<script>
import moment from "moment/moment";
import {list, remove} from "@/api/base";
import {getStaticData} from "@/api/common";

export default {
  name: "JobLog",
  props: {
    jobId: String,
  },
  data() {
    return {
      loading: true,
      editable: false,
      baseUrl: '/monitor/job/log/',
      commonUrl: '/api/system/static/',
      dataList: [],
      pageParam: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
      },
      queryParams: {
        params: {
          executeTime_begin: undefined,
          executeTime_end: undefined
        }
      },
      localDict: {
        dept: [],
        auth_type: []
      },
      dialog: {
        // 是否显示弹出层
        open: false,
        title: "",
      },
      formdata: {
        dept: {},
        users: [],
      },
      formrules: {
        code: [{required: true, message: '请输入应用系统代码', trigger: 'blur'}],
      },
    }
  },
  created() {
    console.log("jobId:" + this.jobId)
    this.getLocalDict()
    this.resetQuery()
  },
  methods: {
    getLocalDict() {
      this.getStaticData('system-quartz-group').then(res => {
        this.localDict.quartz_group = res.data
      })
      this.getStaticData('system-quartz-status').then(res => {
        this.localDict.quartz_status = res.data
      })
      this.getStaticData('system-quartz-result').then(res => {
        this.localDict.quartz_result = res.data
      })
    },
    /** 查询调度日志列表 */
    getList() {
      this.loading = true;
      list(this.baseUrl, {
        ...this.queryParams,
        jobId: this.jobId,
        pageNum: this.pageParam.pageNum,
        pageSize: this.pageParam.pageSize
      }).then(response => {
        this.dataList = response.rows;
        this.pageParam.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.$set(this.queryParams.params, "executeTime_begin", moment().startOf("month").format("YYYY-MM-DD"))
      this.$set(this.queryParams.params, "executeTime_end", moment().endOf("day").format("YYYY-MM-DD"))
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除调度日志编号为"' + ids + '"的数据项？').then(() => {
        remove(this.baseUrl, ids, ids.length > 1).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/monitor/jobLog/exportData', {
        ...this.queryParams
      }, `任务日志导出_${moment().format('YYYY-MM-DD')}.xlsx`, 'application/json;charset=utf-8')
    }
  }
}
</script>

<style scoped>

</style>
